package cn.acewill.wsh.dagger2framedemolearn.app

import android.app.Application
import androidx.annotation.Nullable
import cn.acewill.wsh.dagger2framedemolearn.BuildConfig
import cn.acewill.wsh.dagger2framedemolearn.app.di.AppComponent
import cn.acewill.wsh.dagger2framedemolearn.app.di.AppModule
import cn.acewill.wsh.dagger2framedemolearn.app.di.DaggerAppComponent
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy

/**
 * <pre>
 * @author : zhangyong
 * e-mail : xxx@xx
 * time : 2020/01/09
 * desc :
 * version: 1.0
 * </pre>
 */
class DaggerApp : Application() {
    companion object{
        lateinit var appComponent: AppComponent
    }

    override fun onCreate() {
        super.onCreate()
        initLogger()
        initInjecter()
    }

    private fun initInjecter() {
        appComponent = DaggerAppComponent.builder()
            .appModule(AppModule(this))
            .build()
    }

    private fun initLogger() {
        val pfs = PrettyFormatStrategy.newBuilder()
            .showThreadInfo(true)
            .methodCount(0)
            .methodOffset(7)
            .tag("debuga")
            .build()
        Logger.addLogAdapter(object : AndroidLogAdapter(pfs) {
            override fun isLoggable(priority: Int, @Nullable tag: String?): Boolean {
                return BuildConfig.DEBUG
            }
        })
    }
}